import { dataFromLocalStore, saveToLocalStore, removeFromLocalStore } from './store'

const FAILED_ORDERS = 'FAILED_ORDERS'

export const saveOrder = (str: string) => {
    saveToLocalStore(FAILED_ORDERS, str)
}

export const fetchOrder = (): object | undefined => {
    try {
        const str = dataFromLocalStore(FAILED_ORDERS)
        if (!str) {
            return
        }

        return JSON.parse(str)

    } catch (error) {
        return
    }
}

export const removeOrder = () => {
    removeFromLocalStore(FAILED_ORDERS)
}